import math
import functools
import time
import calendar

strftime=functools.partial(time.strftime,'%Y-%m-%d %H:%M:%S')
int2=functools.partial(int,base=5)

def log(text):
	if isinstance(text,str):
		def f(fun):
			def w(*args,**kw):
				print('方法开始')
				print(text,fun.__name__)
				print('执行时间：',time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))
				st=time.time()			
				a=fun(*args,**kw)
				et=time.time()			
				print('耗时：',et-st,'秒')
				print('方法结束')
				return a
			return w
		return f
	else:
		def wrapper(*args, **kw):
			print('call %s():' % text.__name__)#留个疑问？
			return text(*args, **kw)
		return wrapper

@log('asaks')
def myabs(x):
	if not isinstance(x,(int,float)):
		raise TabError("参数类型有误:"+type(x).__name__)
	if x>0:
		return x
	else:
		return -x


def manyreturn(x,y,z):
	return x,y,z
def porew(x,n=1):
	s=1
	while n>0:
		s=s*x
		n=n-1
	return s

def add_end(L=None):
	if L is None:
		L=[]
	L.append('结束')
	print(L)
	return L

def kebiancanshu(name,*x):
	r=0
	for c in x:
	    r=r+c
	print(name,'-',r)
	return r

def guaniacicanshu(name,age,**kw):
	print('name:',name,'age:',age,'其它:',kw)
#在Python中定义函数，可以用必选参数、默认参数、可变参数、关键字参数和命名关键字参数，
#这5种参数都可以组合使用。但是请注意，参数定义的顺序必须是：必选参数、默认参数、可变参数、命名关键字参数和关键字参数。
#*,后面的参数为命名【关键词参数】  **后面的参数为【关键参数】
#def f1(name,age=20,*arg,*,d,f,**kw):
#	print('name:',name,'age:',age,'d:',d,'f:',f,'kw',kw)

def product(x,*n):
	s=x
	for i in n:
	    s=s*i
	return s
	#if len(n)<=0:
	#	raise TypeError("参数")
	#s=1
	#for x in n:
	#    s=s*x
	#return s
#递归层次过多 会导致堆栈溢出
def fact(n):
	if(n==1):
		return n
	else:
		return n*fact(n-1)
#循环方式 不会导致堆栈溢出
def fact1(n):
	s=1
	if(n==1):
		return n
	else:
		while(n>=1):
			s=s*n
			n=n-1
		return s
def trim(str):	
	while(str[:1]==' '):
		str=str[1:]
	while(str[-1:]==' '):
		str=str[:-1]
	return str
def minandmax(L):
	if len(L)==0:
		return(None,None)
	min=L[0]
	max=L[0]
	for x in L:
		if x<min:
			min=x
		if max<x:
			max=x
	return (min,max)

def findMinAndMax(L):
    if len(L)==0:
        return (None,None)
    else:
        min=max=L[0]
        for m in L:
            if m<=min:
                min=m
            elif m>=max:
                max=m
        return (min,max)
def triangles():
	l = [1]
	while true:
		asa=a
		yield l
		l=[0]+l+[0]
		l=[l[i]+l[i+1] for i in range(len(l)-1)]
def f(x):
	return x*x

def normalize(name):
	name=str(name)
	if len(name)==1:
		return name.upper()
	return name[:1].upper()+name[:-1].lower()
from functools import reduce
def prod(L):
	def a(x,y):
		return x*y
	return reduce(a,L)
def isf(x):
	return x%3==0

def is_palindrome1(n):
	n=str(n)
	istrue=True
	while(istrue and len(n)>0):
		istrue=n[:1]==n[-1:]
		n=n[1:len(n)-1]
	return istrue
def is_palindrome(n):
    istrue=True
    n=str(n)
    while(istrue and len(n)>0):
        istrue=n[:1]==n[-1:]
        n=n[1:len(n)-1]
    return istrue
def by_name(t):
	return -t[1]
def createCounter():
	i=0;
	def counter():
		nonlocal i
		i=i+1
		return i
	return counter

import os

def dir(key):
    path=os.path.abspath('.')
    def _d(path,key):
        for x in os.listdir(path):
            if os.path.isdir(x):
                _d(os.path.join(path,x),key)
            if os.path.isfile(x):
                if key in x:
                    print(x,':',path)
    _d(path,key)